package cn.edu.pku.cs08.liudun.picventure.tools;

import android.app.Activity;
import android.content.Intent;
import android.view.View;

public class SwitchActivityTools {
	
	
	public static void Switch(Activity packageContext, Class<?> cls, 
			boolean isFinish)
	{
		Intent intent = new Intent(packageContext, cls);
		packageContext.startActivity(intent);
		if(isFinish)
			packageContext.finish();
	}
	
	public static void Switch(Activity packageContext, Class<?> cls, int requestCode) {
		Intent intent = new Intent(packageContext, cls);
		packageContext.startActivityForResult(intent, requestCode);
	}
	
	public static boolean SetButton(int btnid, 
			final Activity packageContext, final Class<?> cls, final boolean isFinish)
	{
		View v = packageContext.findViewById(btnid);
		if(v == null)
			return false;
		
		v.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Switch(packageContext, cls, isFinish);
			}
		});
		return true;
	}
}
